package Franction;

import javafx.application.Application;
//import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.geometry.*;
import javafx.scene.shape.Arc;
import javafx.scene.shape.ArcType;
import javafx.stage.Stage;

public class Exercsie14_09 extends Application {
    public void start(Stage stage) {
        GPane pane = new GPane();

        // pane.setPrefSize(400, 400);
        pane.setPadding(new Insets(0, 0, 0, 0));
        pane.setAlignment(Pos.CENTER);
        pane.setHgap(0);
        pane.setVgap(0);
        // for(int i=0; i<2; i++)
        // for(int j=0; j<2; j++)
        // pane.add(new FanPane(), j, i);
        // FanPane p1=new FanPane();

        // FanPane p1=new FanPane(pane)

        Scene scene = new Scene(pane, 400, 400);
        stage.setScene(scene);
        stage.setTitle("Javafx!");
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }

}

class GPane extends GridPane {

    private void paint() {
        this.getChildren().clear();
        double radius = this.getWidth() / 4;
        if (radius > this.getHeight() / 4)
            radius = this.getHeight() / 4;
        this.add(new FanPane(radius), 0, 0);
        this.add(new FanPane(radius), 1, 0);
        this.add(new FanPane(radius), 0, 1);
        this.add(new FanPane(radius), 1, 1);

    }

    public void setWidth(double width) {
        super.setWidth(width);
        paint();
    }

    public void setHeight(double height) {
        super.setHeight(height);
        paint();
    }
}

class FanPane extends Pane {
    private double radius;

    public FanPane(double radius) {
        this.radius = radius;

        paint();
    }

    private void paint() {
        super.getChildren().clear();
        Circle c = new Circle(radius, radius, radius * 0.9);
        c.setFill(Color.WHITE);
        c.setStroke(Color.RED);
        super.getChildren().add(c);
        for (int i = 0; i < 4; i++) {
            Arc arc = new Arc(radius, radius, radius * 0.7, radius * 0.7, 30 + i * 90, 30);
            arc.setFill(Color.RED); // Set fill color
            arc.setType(ArcType.ROUND);
            super.getChildren().add(arc);
        }

    }

    // public void setWidth(double width) {
    // super.setWidth(width);
    // paint();
    // }
    //
    // public void setHeight(double height) {
    // super.setHeight(height);
    // paint();
    // }
}
